import { readWriteMode, VarItem } from "@/api/var";
import { h } from "vue";
import { ElButton } from "element-plus";

const useEquipmentVarColumns = ({
  onEdit,
  onDelete,
}: {
  onEdit: (row: VarItem) => void;
  onDelete: (row: VarItem) => void;
}) => [
  { label: "编号", prop: "id" },
  { label: "变量名称", prop: "varName" },
  { label: "变量单位", prop: "varUnit" },
  { label: "变量标识", prop: "varJson" },
  { label: "变量序号", prop: "varSort" },
  { label: "系数", prop: "coefficient" },
  { label: "数据格式", prop: "dataFormat" },
  { label: "数字格式", prop: "numberFormat" },
  {
    label: "读写方式",
    prop: "readWriteMode",
    formatter: (row: VarItem) => {
      return h("div", [readWriteMode[row.readWriteMode]]);
    },
  },
  {
    label: "操作",
    fixed: "right",
    width: 160,
    formatter: (row: VarItem) => {
      // 操作按钮
      const editButton = h(
        ElButton,
        { link: true, type: "primary", onClick: () => onEdit(row) },
        () => "编辑",
      );
      const delButton = h(
        ElButton,
        { link: true, type: "danger", onClick: () => onDelete(row) },
        () => "删除",
      );
      return h("div", { style: "display: flex" }, [editButton, delButton]);
    },
  },
];

export default useEquipmentVarColumns;
